<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:tw="http://twork.com"
	xmlns:p="http://primefaces.org/ui">


<ui:composition template="/layout/template.xhtml">

	<ui:define name="metadata">
		<f:metadata>
			<f:viewParam name="driverId" value="#{driverHome.driverId}" />
		</f:metadata>
	</ui:define>

	<ui:define name="title">
		<h:outputText value="#{appMsg['title.create.driver']}" rendered="#{driverHome.driver.id eq null}" />
		<h:outputText value="#{appMsg['title.update.driver']}" rendered="#{driverHome.driver.id ne null}" />
	</ui:define>

	<ui:define name="content">
		<h:form id="formDriver">
			<h:panelGrid columns="2">
				<h:outputLabel value="#{appMsg['driver.firstname']}" />
				<p:inputText id="firstname" label="#{appMsg['driver.firstname']}" value="#{driverHome.driver.firstname}"
					required="true">
					<p:ajax event="blur"/>
				</p:inputText>
				<h:outputLabel value="#{appMsg['driver.lastname']}" />
				<p:inputText id="lastname" label="#{appMsg['driver.lastname']}" value="#{driverHome.driver.lastname}"
					required="true">
					<p:ajax event="blur"/>
				</p:inputText>

				<h:outputLabel value="#{appMsg['driver.age']}" />

				<p:inputText id="age" label="#{appMsg['driver.age']}" value="#{driverHome.driver.age}" required="true"
					validator="#{driverHome.validateAge}">
					<p:ajax event="blur"/>
				</p:inputText>


				<h:outputLabel value="#{appMsg['driver.birthdate']}" />
				<p:calendar id="birthdate" pattern="dd/MM/yyyy" label="#{appMsg['driver.birthdate']}"
					value="#{driverHome.driver.birthdate}" required="true" navigator="true" display="inline">
					<p:ajax event="blur"/>
				</p:calendar>

				<h:outputLabel value="#{appMsg['driver.level']}" />
				<p:selectOneMenu id="level" value="#{driverHome.driver.level}">
					<f:selectItem itemValue="" itemLabel="" />
					<f:selectItems value="#{levels.list}" var="w" itemValue="#{w}" itemLabel="#{w.name}" itemKey="#{w.id}" />
					<f:converter converterId="twork.ObjectConverter" />
				</p:selectOneMenu>

				<h:outputLabel value="#{appMsg['driver.team']}" />
				<p:selectOneMenu id="team" value="#{driverHome.driver.team}">
					<!-- does not work with PF 3.4.1 f:selectItem noSelectionOption="true" itemLabel="" / -->
					<f:selectItem itemValue="" itemLabel="" />
					<f:selectItems value="#{teams.list}" var="w" itemValue="#{w}" itemLabel="#{w.name}" itemKey="#{w.id}" />
					<tw:objectConverter />
				</p:selectOneMenu>
			</h:panelGrid>
			<p:commandButton id="merge" ajax="false" actionListener="#{driverHome.doMerge}"
				action="drivers?faces-redirect=true"
				value="#{driverHome.driver.id ne null ? appMsg['update'] : appMsg['create']}" />
			<!--immediate="true" enable NOT to validate the fields, but to execute the action after pahse2 -->
			<p:commandButton id="delete" ajax="false" actionListener="#{driverHome.doDelete}"
				action="drivers?faces-redirect=true" value="#{appMsg['delete']}"
				rendered="#{driverHome.driver.id ne null}" immediate="true"
				onclick="return confirm('#{appMsg['confirm.delete']}#{appMsg['driver']}');" />
			<p:spacer width="6px" />
			<p:commandButton type="reset" value="#{appMsg.reset}" ajax="false" />
			<p:spacer width="6px" />
			<p:button id="cancel" outcome="#{sessionScope['last_GET_in_Session']}?faces-redirect=true"
				value="#{appMsg['cancel']}" />
		</h:form>
	</ui:define>
</ui:composition>
</html>
